<?php
namespace Home\Model;
use Think\Model;

class ArticleModel extends Model {
    //表用了别名 实际表明model_post
    protected $tableName = 'post';
    // 自动验证设置
    protected $_validate = array(
        array('title','require','标题必须！',0, '', self::MODEL_INSERT),
        array('content','require','内容必须'),
        array('title','','标题已经存在',0,'unique',self::MODEL_INSERT),
    );

    // 自动填充设置
    protected $_auto = array(
        array('create_at','time',self::MODEL_INSERT,'function'),
        array('update_at','time',self::MODEL_UPDATE,'function'),
    );

    protected function _after_find(&$result,$options) {
        $result['create_at'] = date('Y-m-d H:i:s', $result['create_at']);
        if($result['update_at'])
            $result['update_at'] = date('Y-m-d H:i:s', $result['update_at']);
        else
            $result['update_at'] = '无';
    }

    protected function _after_select(&$result,$options){
        foreach($result as &$record){
            $this->_after_find($record,$options);
        }
    }

}